<?php

class Indexer_Service_ResultProxy_ZendSearchLucene extends Indexer_Service_ResultProxy
{
    protected $result = array();
    protected $currentIndex = 0;
    
    public $numResults = 0;
    
    public function __construct(&$luceneResult)
    {
        $this->result =& $luceneResult;
        $this->numResults = count($this->result);
        //echo "<pre>({$this->numResults}) "; print_r($this->result); echo "</pre>";
    }
    
    /************** Functions to implement Iterator interface ************/
    
    public function current()
    {
        $hit = $this->result[$this->currentIndex];
        //error_log('Getting Lucene document: '.print_r($hit->getDocument()->getFieldNames(),true));
        $doc = new Indexer_Document($hit->uri); /* @TODO change 'url' to 'uri' */
        $doc->setScore($hit->score);
        $luceneDoc = $hit->getDocument(); /* @var $luceneDoc Zend_Search_Lucene_Document */
        foreach($luceneDoc->getFieldNames() as $fieldName) {
            $doc->setField($fieldName, $luceneDoc->getFieldUtf8Value($fieldName));                
        }
        
        return $doc;
    }
}